package com.dumian.apple.database;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * 数据库里的5张表创建
 * */
public class UserOpenHelper extends SQLiteOpenHelper {
    private static final String TAG = "TestSQLite";
    private  Context mContext;

    public UserOpenHelper(Context context, String name,
                          SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    //     public UserOpenHelper(Context context) {
// /**
//   * ZZChat.db是数据库名字，1是数据库版本。
//   **/
//         super(context, "ZZChat.db", null, 1);
//     }
    @Override
    public void onCreate(SQLiteDatabase db) {
       /**
        * db.execSQL的作用是执行SQL语句，create table User是创建一个叫User的表，括号里就是各个字段名和值类型。
        这里创建了5张表。
        * */
        Log.i(TAG, "_________________________________create Database------------->");

        db.execSQL("create table Users(username varchar(10) primary key,password integer )");
        db.execSQL("create table UserInfo(username varchar(10) primary key,avatar varchar(10)," +
                "sign varchar(50),background varchar(10),state varchar(1))");
        db.execSQL("create table Friends(username varchar(10) primary key,FriendName varchar(10),id int )");
        db.execSQL("create table Groups(GroupName varchar(10) primary key, Creater varchar(10) )");
        db.execSQL("create table GroupInfo(GroupName varchar(10) primary key,groupMemberName varchar(10))");
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //输出更新数据库的日志信息
        Log.i(TAG, "___________________________update Database------------->");

        db.execSQL("drop if table exists Users");
        db.execSQL("drop if table exists  UserInfo");
        db.execSQL("drop if table exists Friends");
        db.execSQL("drop if table exists Groups");
        db.execSQL("drop if table exists GroupInfo");
        onCreate(db);
    }
}
